Socket
Socket
Sign inDemoInstall

bravojs

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bravojs

Implementation of CommonJS Modules/2.0


Version published
Weekly downloads
755
increased by63.07%
Maintainers
1
Install size
862 kB
Created
Weekly downloads
 

Readme

Source

Welcome to BravoJS

  • Copyright (c) 2010-2018 PageMail, Inc.
  • Portions Copyright (c) 2019 Kings Distributed Systems

Released under the terms of the MIT License.

BravoJS began life as a reference implementation of an unratified proposed draft for CommonJS Modules/2.0. Note that the CommonJS working group itself is now defacto defunct, meaning that Modules/2.0 will never become a standard. Other implementations referencing this draft include NobleJS (Domenic Denicola) and PINF (Christoph Dorn). The current draft specification this code is based on has been included in the references directory.

BravoJS is an extensible CommonJS module loader for the web browser and other environments; similar in principle to CommonJS Transport/C (e.g. RequireJS and AMD), but maintaining complete backwards compatibility with CommonJS Modules/1.1.1 modules, including lazy initialization and correct support for dependency graphs with cycles.

The extensibility of this module system makes it possible to write plug-ins to add features like

  • a module loader which resolves dependencies server-side, feeding the module system a cacheable bundle of modules over a single HTTP request
  • a module loader which can operate over a postMessage interface, allowing CommonJS modules to run in Web Workers
  • the only limit is yourself!

We intend to release both Web Worker and NodeJS plugins for BravoJS in the summer of 2019; they will appear in future versions of this package.

As the CommonJS Modules/2.0 specification is no longer being developed we have taken some liberties with BravoJS and are now targeting NodeJS modules and NPM packages in our development efforts. So far, we have

  • added support for replaceable module.exports (although we recommend not using it for new code - there be dragons)
  • included a shim in the utility folder which provides some compatibility between CommonJS Modules/2.0 for and NodeJS (de-sugars the boilerplate module.declare)

Wes Garland, wes@kingsds.network

Compatibility

It is anticipated that core BravoJS continues to work with all browsers, going back as far as Internet Explorer 6, however, we are not testing on obsolete platforms at this time.

Sample Module

module.declare(["list", "of", "dependencies"], function (require, exports, modules) {
  exports.clickyClick = function(element) {
    console.log('You clicked', element.id)
  }
})

Sample Web Application

<html>
<head>
  <script id="bravojs" src="/path/to/bravo.js"></script>
   <style type="text/css">
    BODY[uiState="loading"] * {
      pointer-events: none;
    }
    BODY[uiState="loading"], BODY[uiState="loading"] * {
      opacity: 0.5;
      cursor: wait !important;
    }
  </style>
</head>
<body uiState="loading">
  <form onsubmit="return module.main.validate(this)">
    Click This: 
    <input type="checkbox" id="veryNiceCheckbox" 
           onclick="require('./sampleModule').clickyClick(this)"><br>
    Type Here: 
    <input type="text" name="typing"> 
    <input type="submit" value="OK">
  </form>
  <script>
/** Main module */
module.declare(["./sampleModule"], function(require, exports, module) {
  document.body.setAttribute('uiState', 'ready')

  exports.validate = function(form) {
    console.log("You typed", form.elements['typing'].value)
    return false; /* prevent form from submitting */
  }
})
  </script>
</body>
</html>

Manifest

ResourceDescription
bravo.jsThe CommonJS Modules/2.0 environment with default loader
reference/CommonJS Modules-2.0-draft-8.pdfThe CommonJS Modules/2.0-draft 8 specification
plugins/wonkollA module loader plug-in implemented with LazyLoad.js
plugins/fastloadA module loader plug-in which implements a multi-module transport. Includes server-side component for GPSEE.
plugins/jquery-loaderA module loader plug-in which loads modules over JQuery's version of XHR
demos/areaA web app which calculates the area of a rectangle
demos/iojs_testsAn environment to exercise the Modules/1.0 test suite
demos/readmeA sample module and web app (see above)
utility/cjs2-node.jsA shim to run CommonJS Modules/2.0 modules in NodeJS
utility/test-cjs2-node.shA test runner to run the iojs test suite against cjs2-node.js

Keywords

FAQs

Last updated on 05 Aug 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc